home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
-
- mac_options.c: Copyright (c) Kevin Hammond 1993. All rights reserved.
-
- This module handles the Macintosh options menu.
-
- *****************************************************************************/
-
- #include "mac.h"
- #include "prelude.h"
-
- #pragma segment Options
-
- int AutoLoad = TRUE; /* Is autoloading on */
- int MultiTasking = FALSE; /* or "multitasking" */
- int dummy = TRUE; /* Dummy value for toggles array */
-
- extern int HeapPC;
-
- int Num_stack = NUM_STACK, Num_name = NUM_NAME,
- Num_classes = NUM_CLASSES, Num_insts = NUM_INSTS,
- Num_tycon = NUM_TYCON, Num_tyvars = NUM_TYVARS,
- Num_addrs = NUM_ADDRS, Num_files = NUM_FILES,
- Num_modules = NUM_MODULES, Num_offsets = NUM_OFFSETS,
- Num_tuples = NUM_TUPLES, Num_fixups = NUM_FIXUPS,
- Num_indexes = NUM_INDEXES, Num_syntax = NUM_SYNTAX,
- Num_text = NUM_TEXT, Num_selects = NUM_SELECTS;
-
- /*
- The toggles array contains addresses of the switches controlled
- by option menu commands. These must be *ints*, which causes
- some problems with the original Gofer: Bool seems to be treated
- as a short!
- */
-
- #if !THINKC
- static int *toggles[] = {
- &showStats,
- &gcMessages,
- &addType,
- &literateScripts,
- &coerceNumLiterals,
- &showDicts,
- &traceEval,
- &dummy,
- &AutoLoad,
- &MultiTasking
- };
- #else
- static int *toggles[] = {
- (int *) &showStats,
- (int *) &gcMessages,
- (int *) &addType,
- (int *) &literateScripts,
- (int *) &coerceNumLiterals,
- (int *) &showDicts,
- (int *) &traceEval,
- (int *) &dummy,
- (int *) &AutoLoad,
- (int *) &MultiTasking
- };
- #endif
-
-
- /*
- Initialise the Options menu from the toggles array.
- */
-
- InitOptionMenu()
- {
- short i;
-
- for (i = 1; i <= Option_Toggle_Limit; ++i)
- if(toggles[i-1]!=&dummy)
- CheckItem(Menu_Option,i,(short)(*toggles[i-1]? TRUE: FALSE));
- }
-
-
- /*
- Toggle an item, and set the appropriate flag in the Options menu.
- */
-
- dotoggle(item)
- short item;
- {
- short newtoggle = *toggles[item-1] = !*toggles[item-1];
- CheckItem(Menu_Option,item,newtoggle);
- }
-
-
- /*
- The evidence dialog handles evidence-related options.
- */
-
- doevidencedialog()
- {
- char evidlevel[256];
- DialogPtr eviddlg;
- short itemhit;
- extern int maxEvidLevel;
- int newEvidLevel;
-
- /* Set the cursor */
- SetCursor(&(qd.arrow));
-
- /* Initialise the dialog */
- eviddlg = GetNewDialog(Res_Dlg_Evidence,nil,(WindowPtr) -1);
-
- /* Initialise strings */
- sprintf(evidlevel,"%u",maxEvidLevel);
- SetDlgItemText(eviddlg,Res_DItem_EvidDepth,evidlevel);
-
- /* Set Check Boxes */
- SetDlgItemValue(eviddlg,Res_DItem_AnyEvidence,(short)anyEvidence);
- SetDlgItemValue(eviddlg,Res_DItem_SilentFail, (short)silentEvFail);
-
- /* Now show the window */
- ShowWindow(eviddlg);
-
- /* Highlight the default button */
- highlightDefault(eviddlg);
-
- for(;;)
- {
- ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
- switch(itemhit)
- {
- case OK:
- getitext(gethandle(Res_DItem_EvidDepth,eviddlg),evidlevel);
-
- if((newEvidLevel = atoi(evidlevel)) > 0)
- {
- maxEvidLevel = newEvidLevel;
- anyEvidence = GetCtlValue(getctlhandle(Res_DItem_AnyEvidence,eviddlg));
- silentEvFail = GetCtlValue(getctlhandle(Res_DItem_SilentFail,eviddlg));
-
- DisposDialog(eviddlg);
- return;
- }
- else
- {
- SysBeep(1);
- sprintf(evidlevel,"%u",maxEvidLevel);
- SetDlgItemText(eviddlg,Res_DItem_EvidDepth,evidlevel);
- }
- break;
-
- case CANCEL:
- DisposDialog(eviddlg);
- return;
-
- /* Reset to the defaults. Note these must duplicate the real initial values */
- case DEFAULTS:
- SetDlgItemText (eviddlg,Res_DItem_EvidDepth, "8");
- SetDlgItemValue(eviddlg,Res_DItem_AnyEvidence, TRUE);
- SetDlgItemValue(eviddlg,Res_DItem_SilentFail, TRUE);
- break;
-
- case Res_DItem_AnyEvidence:
- case Res_DItem_SilentFail:
- InvertDlgItemValue(eviddlg,itemhit);
- break;
- }
- }
- }
-
-
- /*
- A structure to hold settings and defaults.
- */
-
-
- struct Settings
- {
- short item; /* Item */
- int *value; /* Address of its value */
- int defaults; /* Default for this item */
- };
-
-
-
- /*
- Settings for the arcana dialog.
- */
-
-
- static struct Settings Arcana [] =
- {
- {Res_DItem_LitErrs, &literateErrors, TRUE},
- {Res_DItem_OptFns, &andorOptimise, TRUE },
- {Res_DItem_FirstErr, &failOnError, TRUE},
- {Res_DItem_TopLevelAmb, &catchAmbigs, FALSE},
- {Res_DItem_PattConf, &useConformality, TRUE },
- {Res_DItem_OverSings, &overSingleton, TRUE },
- {Res_DItem_KindExpert, &kindExpert, FALSE }
- };
-
-
-
- /*
- The arcana dialog handles obscure, but possibly useful Gofer options.
- */
-
- doarcanadialog()
- {
- DialogPtr arcanadlg;
- short itemhit;
- int i;
-
- /* Set the cursor */
- SetCursor(&(qd.arrow));
-
- /* Initialise the dialog */
- arcanadlg = GetNewDialog(Res_Dlg_Arcana,nil,(WindowPtr) -1);
-
- /* Set Check Boxes */
- for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
- SetDlgItemValue(arcanadlg, Arcana[i].item, *(Arcana[i].value));
-
- /* Now show the window */
- ShowWindow(arcanadlg);
-
- /* Highlight the default button */
- highlightDefault(arcanadlg);
-
- for(;;)
- {
- ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
- switch(itemhit)
- {
- case OK:
- for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
- *(Arcana[i].value) = GetCtlValue(getctlhandle(Arcana[i].item,arcanadlg));
-
- case CANCEL:
- DisposDialog(arcanadlg);
- return;
-
- case DEFAULTS:
- for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
- SetDlgItemValue(arcanadlg, Arcana[i].item, Arcana[i].defaults);
- break;
-
- case Res_DItem_LitErrs:
- case Res_DItem_OptFns:
- case Res_DItem_FirstErr:
- case Res_DItem_TopLevelAmb:
- case Res_DItem_PattConf:
- case Res_DItem_OverSings:
- case Res_DItem_KindExpert:
- InvertDlgItemValue(arcanadlg,itemhit);
- break;
- }
- }
- }
-
-
- /*
- Settings for the memory dialog.
-
- On startup, the first item in the array will be highlighted: this should
- be the first item in the dialog or it will look odd.
- */
-
- static struct Settings MemDlg [] =
- {
- {Res_DItem_HeapPC, &HeapPC, DEFAULT_HEAP_PERCENTAGE},
- {Res_DItem_StackSize, &Num_stack, NUM_STACK},
- {Res_DItem_Names, &Num_name, NUM_NAME},
- {Res_DItem_Classes, &Num_classes, NUM_CLASSES},
- {Res_DItem_Instances, &Num_insts, NUM_INSTS},
- {Res_DItem_Tycons, &Num_tycon, NUM_TYCON},
- {Res_DItem_Tyvars, &Num_tyvars, NUM_TYVARS},
- {Res_DItem_Offsets, &Num_offsets, NUM_OFFSETS},
- {Res_DItem_Addresses, &Num_addrs, NUM_ADDRS},
- {Res_DItem_Fixups, &Num_fixups, NUM_FIXUPS},
- {Res_DItem_Syntax, &Num_syntax, NUM_SYNTAX},
- {Res_DItem_Selectors, &Num_selects, NUM_SELECTS},
- {Res_DItem_HeapSize, &heapSize, DEFAULTHEAP}
- };
-
- /* Which of the above are the Heap Percentage item and the Heap Size item */
- #define HeapPCItem 0
- #define HeapSizeItem (sizeof(MemDlg)/sizeof(struct Settings) - 1)
-
- domemorydialog()
- {
- DialogPtr memdlg;
- short itemhit;
- int i;
- int oldHeapPC = HeapPC;
-
- /* Set the cursor */
- SetCursor(&(qd.arrow));
-
- /* Initialise the dialog */
- memdlg = GetNewDialog(Res_Dlg_Memory,nil,(WindowPtr) -1);
-
- for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
- SetDlgItemETVal(memdlg, MemDlg[i].item, *(MemDlg[i].value));
-
- MemDlg[HeapSizeItem].defaults = *(MemDlg[HeapSizeItem].value);
-
- /* Now show the window */
- ShowWindow(memdlg);
-
- /* Highlight the default button */
- highlightDefault(memdlg);
-
- for(;;)
- {
- modal:
- ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
- switch(itemhit)
- {
- case OK:
- for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
- if(!GetDlgItemETVal(memdlg, MemDlg[i].item, MemDlg[i].value) ||
- MemDlg[i].value < 0)
- {
- SysBeep(1);
- /* Goto is necessary here, since break would only exit the for loop */
- goto modal;
- }
-
- /* Keep the heap percentage sensible */
- if(*(MemDlg[HeapPCItem].value) > 99)
- {
- StopAlert(Res_HeapPCTooHigh_Alert,NIL);
- HeapPC = oldHeapPC;
- SetDlgItemETVal(memdlg, MemDlg[HeapPCItem].item, HeapPC);
- break;
- }
-
- case CANCEL:
- DisposDialog(memdlg);
- return;
-
- case DEFAULTS:
- for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
- SetDlgItemETVal(memdlg, MemDlg[i].item, MemDlg[i].defaults);
- break;
-
- default:
- break;
- }
- }
- }
-
-